<template>
  <div>

    <!--     搜索条件-->
    <SearchForm @search="getTableData" @reset="clearSearch">
      <el-col :span="8" :xs="24" v-show="$permiss[600]">
        <el-form-item :label="$t('所属租户')" prop="adminUserId">
          <el-select v-model="page.adminUserId" style="width: 100%" clearable>
            <el-option v-for="item in tenantList" :key="item.adminUserId" :label="item.adminName"
                       :value="item.adminUserId"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="8" :xs="24" v-show="$permiss[601]">
        <el-form-item :label="$t('产品ID')" prop="productName">
          <el-select v-model="page.productName" style="width: 100%" filterable clearable :placeholder="$t('请选择APP')">
            <el-option v-for="item in productList" :key="item.productId" :value="item.productName"
                       :label="item.productName"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="8" :xs="24">
        <el-form-item :label="$t('上架类型')" prop="listType">
          <el-select v-model="page.listType" style="width: 100%" clearable>
            <el-option :label="$t('非上架APP')" :value="0"></el-option>
            <el-option :label="$t('上架APP')" :value="1"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="8" :xs="24">
        <el-form-item :label="$t('APP类型')" prop="appType">
          <el-select v-model="page.appType" style="width: 100%" clearable>
            <el-option label="H5" :value="1"></el-option>
            <el-option label="APP" :value="0"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="8" :xs="24">
        <el-form-item :label="$t('状态')" prop="status">
          <el-select v-model="page.status" style="width: 100%" clearable>
            <el-option :value="1" :label="$t('启用')"></el-option>
            <el-option :value="0" :label="$t('禁用')"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
    </SearchForm>
    <el-card shadow="never" style="margin-top: 10px">
      <Table :table-data="tableData" :table-column="tableColumn" row-key="id" :page="page"
             @handleSizeChange="handleSizeChange"
             :loading="loading"
             @handleCurrentChange="handleCurrentChange">
        <template slot="isH5" slot-scope="{row}">
          {{ row.isH5 === 1 ? 'H5' : 'APP' }}
        </template>
        <template slot="status" slot-scope="{row}">
          <el-switch :disabled="!$permiss[127]" @change="changeStatus(row)"
                     :value="row.status"></el-switch>
        </template>
        <template slot="handle" slot-scope="{row}">
          <el-dropdown>
                   <span class="el-dropdown-link">
                     <el-link type="primary" :underline="false">{{ $t('操作') }}</el-link>
                   <i class="el-icon-arrow-down el-icon--right" style="color: #ff8a00;font-size: 12px"></i>
                 </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="look(row)" v-show="$permiss[128]">{{
                  $t('编辑产品')
                }}
              </el-dropdown-item>
              <el-dropdown-item @click.native="clickRows(row,'bind')" v-show="$permiss[394]">{{
                  $t('绑定规则')
                }}
              </el-dropdown-item>
              <el-dropdown-item @click.native="clickRows(row,'comprehensive')" v-show="$permiss[406]">{{
                  $t('综合设置')
                }}
              </el-dropdown-item>
              <el-dropdown-item @click.native="clickRows(row,'auditProcess')" v-show="$permiss[619]">{{
                  $t('审核流程设置')
                }}
              </el-dropdown-item>
              <el-dropdown-item @click.native="clickRows(row,'about')" v-show="$permiss[128]">{{
                  $t('APP文案设置')
                }}
              </el-dropdown-item>
              <el-dropdown-item @click.native="clickRows(row,'distribution')" v-show="$permiss[128]">{{
                  $t('分单设置')
                }}
              </el-dropdown-item>
              <el-dropdown-item @click.native="clickRows(row,'bindSms')" v-show="$permiss[1550]">{{
                  $t('绑定短信')
                }}
              </el-dropdown-item>
              <el-dropdown-item @click.native="clickRows(row,'bindUserLabel')" v-show="$permiss[1652]">{{
                  $t('绑定用户标签')
                }}
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </Table>
    </el-card>
    <!--    综合设置-->
    <Dialog :visible.sync="comprehensiveVisible" :title="visibleProductTitle + ' - ' +  $t('综合设置') " width="70%"
            @confirm="comprehensiveConfirm"
            @cancel="comprehensiveVisible = false" @close="comprehensiveClear" :footer="$permiss[577] ? true : false">
      <el-form :model="comprehensiveForm" ref="comprehensiveForm" label-position="left">
        <!--      拉黑设置-->
        <div class="comprehensive_box">
          <div class="title">{{ $t('拉黑设置') }}</div>
          <div class="content">
            <el-row :gutter="24" style="margin: 0">
              <el-col :span="12" style="padding: 0">
                <el-input v-model="comprehensiveForm.needOverdueDays">
                  <template slot="prepend"> {{ $t('拉黑所需逾期天数') }}</template>
                </el-input>
              </el-col>
            </el-row>
          </div>
        </div>
        <!--      进件规则设置设置-->
        <div class="comprehensive_box">
          <div class="title">{{ $t('进件设置') }}</div>
          <div class="content">
            <!--            <el-input v-model="comprehensiveForm.reBorrowNumber">-->
            <!--              <template slot="prepend"> {{ $t('复借大于等于') }}</template>-->
            <!--              <template slot="append">{{ $t('次则拒绝进件申请') }}</template>-->
            <!--            </el-input>-->
            <div :gutter="24" style="margin-top:10px">
              <el-input oninput="if(value>=23)value=23;if(value<=0)value=''" v-model="comprehensiveForm.loanStartTime">
                <template slot="prepend"> {{ $t('不允许新客户在每日') }}</template>
              </el-input>
              <span style="padding: 0 10px">-</span>
              <el-input oninput="if(value>=23)value=23;if(value<=0)value=''" v-model="comprehensiveForm.loanEndTime">
                <template slot="append">{{ $t('时间范围内进件') }}</template>
              </el-input>
            </div>
            <div style="margin-top: 10px">
              <el-input oninput="if(value>=23)value=23;if(value<=0)value=''"
                        v-model="comprehensiveForm.oldLoanStartTime">
                <template slot="prepend"> {{ $t('不允许老客户在每日') }}</template>
              </el-input>
              <span style="padding: 0 10px">-</span>
              <el-input oninput="if(value>=23)value=23;if(value<=0)value=''" v-model="comprehensiveForm.oldLoanEndTime">
                <template slot="append">{{ $t('时间范围内进件') }}</template>
              </el-input>
            </div>
            <div style="margin-top: 10px">
              <el-input v-model="comprehensiveForm.nextLoanTime">
                <template slot="prepend"> {{ $t('客户在系统中其他APP订单被拒绝') + ',' }}</template>
                <template slot="append">{{ $t('天后可在本APP重新提交进件申请') }}</template>
              </el-input>
            </div>
            <div style="margin-top: 10px">
              <el-input v-model="comprehensiveForm.appNextLoanTime">
                <template slot="prepend"> {{ $t('客户在本APP中订单被拒绝') + ',' }}</template>
                <template slot="append">{{ $t('天后可在本APP重新提交进件申请') }}</template>
              </el-input>
            </div>
            <div style="margin-top: 10px">
              <el-input v-model="comprehensiveForm.firstBorrowNumber">
                <template slot="prepend"> {{ $t('APP中默认显示可借') }}</template>
                <template slot="append">{{ $t('个产品') }}</template>
              </el-input>
            </div>

          </div>
        </div>

        <!--      服务项设置-->
        <div class="comprehensive_box">
          <div class="title">{{ $t('服务项设置') }}</div>
          <div class="content">
            <el-row :gutter="24" style="margin: 0">
              <el-col :span="6" style="padding: 0">
                <el-form-item :label="$t('身份校验')" prop="identityCheck">
                  <div style="line-height: 32px">
                    <el-switch :value="comprehensiveForm.identityCheck === 1"
                               @change="changeServiceStatus('identityCheck')"/>
                  </div>
                </el-form-item>

              </el-col>
              <el-col :span="6" style="padding: 0">
                <el-form-item :label="$t('风控评分')" prop="score">
                  <div style="line-height: 32px">
                    <el-switch :value="comprehensiveForm.score  === 1"
                               @change="changeServiceStatus('score')"/>
                  </div>
                </el-form-item>
              </el-col>
              <el-col :span="6" style="padding: 0">
                <el-form-item label="OCR" prop="ocrSwitch">
                  <div style="line-height: 32px">
                    <el-switch :value="comprehensiveForm.ocrSwitch  === 1"
                               @change="changeServiceStatus('ocrSwitch')"/>
                  </div>
                </el-form-item>
              </el-col>
              <el-col :span="6" style="padding: 0">
                <el-form-item :label="$t('活体验证')" prop="livingSwitch">
                  <div style="line-height: 32px">
                    <el-switch :value="comprehensiveForm.livingSwitch  === 1"
                               @change="changeServiceStatus('livingSwitch')"/>
                  </div>
                </el-form-item>
              </el-col>
              <el-col :span="6" style="padding: 0">
                <el-form-item :label="$t('黑名单')" prop="blacklistSwitch">
                  <div style="line-height: 32px">
                    <el-switch :value="comprehensiveForm.blacklistSwitch  === 1"
                               @change="changeServiceStatus('blacklistSwitch')"/>
                  </div>
                </el-form-item>
              </el-col>

              <el-col :span="6" style="padding: 0">
                <el-form-item :label="$t('人脸黑名单')" prop="faceBlacklistSwitch">
                  <div style="line-height: 32px">
                    <el-switch :value="comprehensiveForm.faceBlacklistSwitch  === 1"
                               @change="changeServiceStatus('faceBlacklistSwitch')"/>
                  </div>
                </el-form-item>
              </el-col>
              <el-col :span="6" style="padding: 0">
                <el-form-item :label="$t('人脸对比')" prop="faceSwitch">
                  <div style="line-height: 32px">
                    <el-switch :value="comprehensiveForm.faceSwitch  === 1"
                               @change="changeServiceStatus('faceSwitch')"/>
                  </div>
                </el-form-item>
              </el-col>
              <el-col :span="6" style="padding: 0">
                <el-form-item label-width="110px" :label="$t('第三方多头报告')" prop="complexDetectionSwitch">
                  <div style="line-height: 32px">
                    <el-switch :value="comprehensiveForm.complexDetectionSwitch  === 1"
                               @change="changeServiceStatus('complexDetectionSwitch')"/>
                  </div>
                </el-form-item>
              </el-col>
              <!--              墨西哥专属配置-->
              <el-col :span="6" style="padding: 0">
                <el-form-item label-width="80px" :label="$t('税卡校验')" prop="rfc">
                  <div style="line-height: 32px">
                    <el-switch :value="comprehensiveForm.rfc  === 1"
                               @change="changeServiceStatus('rfc')"/>
                  </div>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </div>
        <!--      注册设置-->
        <div class="comprehensive_box">
          <div class="title">{{ $t('注册设置') }}</div>
          <div class="content">
            <el-row :gutter="24" style="margin: 0">
              <el-col :span="6" style="padding: 0">
                <el-form-item label-width="110px" :label="$t('仅白名单可注册')">
                  <div style="line-height: 32px">
                    <el-switch :value="comprehensiveForm.isWhiteListInput  === 1"
                               @change="changeRegisterStatus()"/>
                  </div>
                </el-form-item>
              </el-col>
              <el-col :span="24" style="margin-bottom: 10px">
                <el-input v-model="comprehensiveForm.overdueUncleared"
                          oninput="value = value.replace(/[^\d.]/g, '')">
                  <template slot="prepend"> {{ $t('客户在系统内存在逾期大于等于') }}</template>
                  <template slot="append">{{ $t('天且还未结清，则不予许在当前APP进件') }}</template>
                </el-input>
              </el-col>
            </el-row>
          </div>
        </div>
        <!--      审核设置-->
        <div class="comprehensive_box">
          <div class="title">{{ $t('审核设置') }}</div>
          <div class="content">
            <el-row :gutter="24" style="margin: 0">
              <el-col :span="6" style="padding: 0">
                <el-form-item :label="$t('自动免审')">
                  <div style="line-height: 32px">
                    <el-switch :value="comprehensiveForm.avoidAudit === 1"
                               @change="examineFormChange('avoidAudit',$event)"></el-switch>
                  </div>
                </el-form-item>
              </el-col>
              <el-col :span="6" style="padding: 0">
                <el-form-item :label="$t('新客秒拒')">
                  <div style="line-height: 32px">
                    <el-switch :value="comprehensiveForm.machineNewRefuse === 1"
                               @change="examineFormChange('machineNewRefuse',$event)"></el-switch>
                  </div>
                </el-form-item>
              </el-col>
              <el-col :span="6" style="padding: 0">
                <el-form-item :label="$t('新客秒过')">
                  <div style="line-height: 32px">
                    <el-switch :value="comprehensiveForm.machineNewPass === 1"
                               @change="examineFormChange('machineNewPass',$event)"></el-switch>
                  </div>
                </el-form-item>
              </el-col>
              <el-col :span="6" style="padding: 0">
                <el-form-item :label="$t('老客秒拒')">
                  <div style="line-height: 32px">
                    <el-switch :value="comprehensiveForm.machineOldRefuse === 1"
                               @change="examineFormChange('machineOldRefuse',$event)"></el-switch>
                  </div>
                </el-form-item>
              </el-col>
              <el-col :span="6" style="padding: 0">
                <el-form-item :label="$t('老客秒过')">
                  <div style="line-height: 32px">
                    <el-switch :value="comprehensiveForm.machineOldPass === 1"
                               @change="examineFormChange('machineOldPass',$event)"></el-switch>
                  </div>
                </el-form-item>
              </el-col>
              <el-col :span="24" style="margin-bottom: 10px">
                <el-input v-model="comprehensiveForm.newAuditFreeScore" oninput="value = value.replace(/[^\d.]/g, '');">
                  <template slot="prepend"> {{ $t('新客黑猫分高于') }}</template>
                  <template slot="append">{{ $t('分，订单直接通过(机审规则全部通过的前提下)') }}</template>
                </el-input>
                <span style="margin-left: 15px" v-show="comprehensiveForm.newAuditFreeScore > 0">
                              <el-checkbox :value="comprehensiveForm.newIsOperators=== 1"
                                           @change="(value)=>{comprehensiveForm.newIsOperators = value ? 1:0}">{{
                                  $t('存在运营商记录')
                                }}</el-checkbox>
                              </span>
              </el-col>
              <el-col :span="24" style="margin-bottom: 10px">
                <el-input v-model="comprehensiveForm.oldAuditFreeScore" oninput="value = value.replace(/[^\d.]/g, '');">
                  <template slot="prepend"> {{ $t('老客黑猫分高于') }}</template>
                  <template slot="append">{{ $t('分，订单直接通过(机审规则全部通过的前提下)') }}</template>
                </el-input>
                <span style="margin-left: 15px" v-show="comprehensiveForm.oldAuditFreeScore > 0">
                              <el-checkbox :value="comprehensiveForm.oldIsOperators === 1"
                                           @change="(value)=>{comprehensiveForm.oldIsOperators = value ? 1:0}">{{
                                  $t('存在运营商记录')
                                }}</el-checkbox>
                              </span>
              </el-col>
            </el-row>
          </div>
        </div>
        <!--              共债设置-->
        <div class="comprehensive_box">
          <div class="title">{{ $t('共债设置') }}</div>
          <div class="content">
            <el-row :gutter="24" style="margin: 0">
              <el-col :span="6" style="padding: 0">
                <el-form-item label-width="80px" :label="$t('新客共债')">
                  <div style="line-height: 32px">
                    <el-switch :value="comprehensiveForm.isNewDebt  === 1"
                               @change="changeIsNewDebt('isNewDebt',$event)"/>
                  </div>
                </el-form-item>
              </el-col>
              <el-col :span="6" style="padding: 0">
                <el-form-item label-width="80px" :label="$t('老客共债')">
                  <div style="line-height: 32px">
                    <el-switch :value="comprehensiveForm.isOldDebt  === 1"
                               @change="changeIsNewDebt('isOldDebt',$event)"/>
                  </div>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </div>
        <!--              运营商认证设置-->
        <div class="comprehensive_box">
          <div class="title">{{ $t('运营商认证设置') }}</div>
          <div class="content">
            <el-input v-model="comprehensiveForm.operatorAging" oninput="value = value.replace(/[^\d]/g, '')">
              <template slot="prepend"> {{ $t('客户营运商认证成功后') }}</template>
              <template slot="append">{{ $t('天内无需重复认证') }}</template>
            </el-input>
          </div>
        </div>
      </el-form>
    </Dialog>
    <!--     关于我们设置-->
    <Dialog :visible.sync="visibleAbout" :title="visibleProductTitle + ' - ' +  $t('APP文案设置')"
            @confirm="visibleAboutConfirm"
            @close="aboutClearForm" @cancel="visibleAbout = false" :footer="$permiss[405] ? true : false">
      <!--      关于我们设置-->
      <div class="comprehensive_box">
        <div class="title">{{ $t('关于我们设置') }}</div>
        <div style="margin-top: 15px">
          <el-form ref="aboutForm" :model="aboutForm" label-width="80px">
            <el-form-item :label="$t('联系电话')" prop="servicePhone">
              <el-input style="width: 100%" v-model="aboutForm.servicePhone"/>
            </el-form-item>
            <el-form-item :label="$t('邮箱')" prop="mail">
              <el-input style="width: 100%" v-model="aboutForm.mail"/>
            </el-form-item>
            <el-form-item :label="$t('产品介绍')" prop="aboutContent">
              <el-input type="textarea" :rows="6" v-model="aboutForm.aboutContent"/>
            </el-form-item>
          </el-form>
        </div>
      </div>
      <!--      虚拟卡提示设置-->
      <div class="comprehensive_box">
        <div class="title">{{ $t('虚拟卡提示设置') }}</div>
        <div style="margin-top: 15px">
          <el-form ref="aboutForm" :model="aboutForm" label-width="100px">
            <el-form-item :label="$t('展期虚拟卡')" prop="servicePhone">
              <el-input type="textarea" :rows="5" v-model="aboutForm.rolloverContent"/>
            </el-form-item>
            <el-form-item :label="$t('还款虚拟卡')" prop="mail">
              <el-input type="textarea" :rows="5" v-model="aboutForm.repaymentContent"/>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </Dialog>
    <!--    审核流程设置-->
    <Dialog :visible.sync="visibleAuditProcess" :title="visibleProductTitle + ' - ' + $t('审核流程设置')" width="750px"
            @cancel="visibleAuditProcess = false" :footer="$permiss[620] ? true : false" @confirm="confirmAuditProcess">
      <!--        新客初审-->
      <div style="display:flex;justify-content: center">
        <div class="cursor_pointer" style="text-align: center" @click="changeAuditProcess('new')">
          <img style="height: 70px;width: 70px" :src="newComplete"/>
          <div class=" audit_text" :class="{audit_text_active:auditForm.newIsFirstTrial === 1}">
            <span>{{ $t('新客初审') }}</span>
          </div>
        </div>
        <div style="line-height: 100px;padding: 0 20px">
          <img style="width:400px;" :src="newArrow">
        </div>
        <div style="text-align: center">
          <img style="height: 70px;width: 70px" src="../../../assets/circular@2x.png"/>
          <div class="audit_text audit_text_active">
            <span>{{ $t('新客终审') }}</span>
          </div>
        </div>
      </div>
      <!--        老客初审-->
      <div style="display:flex;justify-content: center;margin-top: 30px">
        <div style="text-align: center" class="cursor_pointer" @click="changeAuditProcess('old')">
          <img style="height: 70px;width: 70px" :src="oldComplete"/>
          <div class="audit_text" :class="{audit_text_active:auditForm.oldIsFirstTrial === 1}">
            <span>{{ $t('老客初审') }}</span>
          </div>
        </div>
        <div style="line-height: 100px; padding: 0 20px">
          <img style="width:400px;" :src="oldArrow">
        </div>
        <div style="text-align: center">
          <img style="height: 70px;width: 70px" src="../../../assets/circular@2x.png"/>
          <div class="audit_text audit_text_active">
            <span>{{ $t('老客终审') }}</span>
          </div>
        </div>
      </div>
      <el-alert
          style="margin-top: 15px"
          :title="$t('开启初审流程时,请及时创建并绑定好负责该APP业务的初审专员账号')"
          type="info"
          show-icon
          :closable="false">
      </el-alert>
    </Dialog>
    <!--    绑定规则-->
    <BindingRules :visibleBindRules.sync="visibleBindRules" :rows="tableRows"></BindingRules>

    <!--   分单设置  -->
    <BistributeSet :visibleBistributeSet.sync="visibleBistributeSet" :rows="tableRows"
                   @confirm="getTableData"></BistributeSet>

    <!-- 绑定短信-->
    <BindSms :visibleBindSms.sync="visibleBindSms" :rows="tableRows"></BindSms>

    <!--    绑定用户标签-->
    <BindUserLabel :visibleBindUserLabel.sync="visibleBindUserLabel" :rows="tableRows"/>
  </div>
</template>

<script>
import BindingRules from './components/bindingRules'
import BistributeSet from "./components/bistributeSet";
import {selectProduct, selectTenant} from "@/api/system";
import {
  updateTenantProduct,
  fetchProductList,
  getAboutByProductName,
  replaceInsertAbout,
  firstTrialSwitch,
  updateStatusProduct
} from '@/api/product'
// 绑定短信
import BindSms from "./components/bindSms";
// 绑定用户标签
import BindUserLabel from "./components/bindUserLabel";

export default {
  name: 'productList',
  data() {
    const {$permiss} = this
    return {
      page: {
        pageNum: 1,
        pageSize: 10,
        total: 0
      },
      loading: false,
      productList: [],
      tableData: [],
      tableColumn: [
        {label: this.$t('所属租户'), prop: 'adminUserName', align: 'center', isHide: !$permiss[600]},
        {label: this.$t('产品ID'), prop: 'productName', align: 'center',},
        {label: this.$t('APP名称'), prop: 'appName', align: 'center',},
        {label: this.$t('APP类型'), prop: 'isH5', slot: 'isH5', align: 'center',},
        {label: this.$t('上架类型'), prop: 'listType', align: 'center',},
        {label: this.$t('新建时间'), prop: 'creationTime', align: 'center',},
        {label: this.$t('状态'), slot: 'status', align: 'center',},
        {
          label: this.$t('操作'),
          slot: 'handle',
          align: 'center',
          isHide: !$permiss[128] && !$permiss[394] && !$permiss[406] && !$permiss[619] && !$permiss[128]
        },
      ],
      visibleAbout: false,
      visibleBindRules: false,
      comprehensiveVisible: false,
      visibleAuditProcess: false,
      visibleBistributeSet: false,
      auditForm: {
        newIsFirstTrial: 0,
        oldIsFirstTrial: 0,
      },
      comprehensiveForm: {},
      visibleProductTitle: '',
      aboutForm: {},
      tableRows: {},
      tenantList: [],
      visibleBindSms: false,
      visibleBindUserLabel: false
    }
  },
  computed: {
    newComplete() {
      return this.auditForm.newIsFirstTrial === 0 ? require('../../../assets/complete@2x.png') : require('../../../assets/complete_active.png')
    },
    oldComplete() {
      return this.auditForm.oldIsFirstTrial === 0 ? require('../../../assets/complete@2x.png') : require('../../../assets/complete_active.png')
    },
    newArrow() {
      return this.auditForm.newIsFirstTrial === 0 ? require('../../../assets/arrow@2x.png') : require('../../../assets/arrow_active@2x.png')
    },
    oldArrow() {
      return this.auditForm.oldIsFirstTrial === 0 ? require('../../../assets/arrow@2x.png') : require('../../../assets/arrow_active@2x.png')
    },
  },
  components: {
    BindSms,
    BindingRules,
    BistributeSet,
    BindUserLabel
  },
  mounted() {
    this.getTableData()
    this.getSelect()
  },
  methods: {
    async getSelect() {
      this.tenantList = await selectTenant().then(res => res.data)
      this.productList = await selectProduct().then(res => res.data)
    },
    async getTableData() {
      const params = {
        ...this.page
      }
      this.loading = true
      const res = await fetchProductList(params)
      if (res.code === 1) {
        const {list, total} = res.data
        this.tableData = list.filter(item => {
          item.status = item.status === 1
          item.listType = item.listType === 1 ? this.$t('上架APP') : this.$t('非上架APP')
          return item
        })
        this.page = Object.assign({}, this.page, {
          total: total
        })
        this.loading = false
      } else {
        this.loading = false
      }
    },
    async changeStatus(row) {
      const res = await updateStatusProduct({
        productId: row.productId,
        productName: row.productName,
        status: row.status ? 0 : 1,
        adminProductId: row.adminProductId
      })
      if (res.code === 1) {
        this.$message.success(this.$t('修改成功'))
        this.getTableData()
      }
    },
    handleSizeChange(val) {
      this.page.pageSize = val
      this.getTableData()
    },
    handleCurrentChange(val) {
      this.page.pageNum = val
      this.getTableData()
    },
    clearSearch() {
      this.page = {
        pageNum: 1,
        pageSize: 10,
        total: 0
      }
      this.getTableData()
    },
    clickRows(row, type) {
      this.tableRows = {...row}
      this.visibleProductTitle = row.productName
      switch (type) {
        case 'bind' :
          this.bindingRules()
          break;
        case 'about' :
          this.aboutSet()
          break;
        case 'auditProcess':
          this.setAuditProcess()
          break;
        case 'comprehensive' :
          this.comprehensiveForm = {...this.tableRows}
          this.comprehensiveVisible = true
          break
        case 'distribution' :
          this.visibleBistributeSet = true;
          break;
        case 'bindSms' :
          this.visibleBindSms = true
          break;
        case 'bindUserLabel' :
          this.visibleBindUserLabel = true
      }
    },
    // 综合设置提交
    async comprehensiveConfirm() {
      const {
        productId,
        needOverdueDays,
        reBorrowNumber,
        nextLoanTime,
        appNextLoanTime,
        oldLoanStartTime,
        oldLoanEndTime,
        isWhiteListInput,
        score, identityCheck,
        machineOldRefuse, machineOldPass,
        machineNewRefuse, machineNewPass,
        avoidAudit, livingSwitch, ocrSwitch,
        operatorAging,
        rfc,
        blacklistSwitch,
        firstBorrowNumber,
        newAuditFreeScore,
        overdueUncleared,
        oldAuditFreeScore,
        newIsOperators,
        oldIsOperators,
        loanStartTime, loanEndTime, complexDetectionSwitch, faceSwitch, faceBlacklistSwitch, isOldDebt, isNewDebt
      } = this.comprehensiveForm
      const params = {
        productId,
        needOverdueDays,
        reBorrowNumber,
        nextLoanTime,
        appNextLoanTime,
        isWhiteListInput,
        score,
        identityCheck,
        machineOldRefuse,
        machineOldPass,
        machineNewRefuse,
        machineNewPass,
        avoidAudit,
        livingSwitch,
        ocrSwitch,
        blacklistSwitch,
        complexDetectionSwitch, faceSwitch, faceBlacklistSwitch,
        isOldDebt, isNewDebt,
        operatorAging,
        firstBorrowNumber,
        rfc,
        newAuditFreeScore,
        oldAuditFreeScore,
        overdueUncleared,
        newIsOperators: !parseInt(newAuditFreeScore) ? 0 : newIsOperators ? 1 : 0,
        oldIsOperators: !parseInt(oldAuditFreeScore) ? 0 : oldIsOperators ? 1 : 0,
        loanStartTime: loanStartTime ? parseInt(loanStartTime) : undefined,
        loanEndTime: loanEndTime ? parseInt(loanEndTime) : undefined,
        oldLoanStartTime: oldLoanStartTime ? parseInt(oldLoanStartTime) : undefined,
        oldLoanEndTime: oldLoanEndTime ? parseInt(oldLoanEndTime) : undefined
      }
      const res = await updateTenantProduct(params)
      if (res.code === 1) {
        this.$message.success(this.$t('操作成功'))
        this.comprehensiveVisible = false
        this.getTableData()
      }
    },
    // 清空综合设置
    comprehensiveClear() {
      // 默认开启
      this.comprehensiveForm = {}
    },
    //注册设置状态切换
    changeRegisterStatus() {
      this.comprehensiveForm.isWhiteListInput === 0 ? this.comprehensiveForm.isWhiteListInput = 1 : this.comprehensiveForm.isWhiteListInput = 0
    },
    // 服务项设置状态切换
    changeServiceStatus(type) {
      if (type === 'faceSwitch') {
        // 开启人脸对比 自动开启ocr和活体验证
        const faceSwitch = this.comprehensiveForm['faceSwitch']
        if (faceSwitch) {
          this.comprehensiveForm['faceSwitch'] = 0
        } else {
          this.$set(this.comprehensiveForm, 'faceSwitch', 1)
          this.$set(this.comprehensiveForm, 'livingSwitch', 1)
          this.$set(this.comprehensiveForm, 'ocrSwitch', 1)
        }
      } else if (this.comprehensiveForm[type]) {
        // 开关关闭
        if ((type === 'livingSwitch' || type === 'ocrSwitch') && this.comprehensiveForm['faceSwitch'] === 1) {
          return this.$message.error(this.$t('开启人脸对比时，需同时打开OCR和活体验证'))
        }
        this.comprehensiveForm[type] = this.comprehensiveForm[type] === 1 ? 0 : 1
      } else {
        // 开关开启
        this.$set(this.comprehensiveForm, type, 1)
      }
    },
    // 综合设置切换
    changeIsNewDebt(type, value) {
      const confirm = () => {
        this.comprehensiveForm[type] = value ? 1 : 0
      }
      if (value) {
        this.$confirm(this.$t('当前状态改变后对业务可能造成影响和风险,请慎重操作'), this.$t('提示'), {
          type: 'warning'
        }).then(() => {
          confirm()
        }).catch(() => {
        })
      } else {
        confirm()
      }
    },
    // 绑定规则
    bindingRules() {
      this.visibleBindRules = true
    },
    // 关于我们
    async aboutSet() {
      const {productName} = this.tableRows
      const res = await getAboutByProductName({productName})
      if (res.code === 1) {
        this.aboutForm = res.data ? res.data : {}
        this.visibleAbout = true
      }
    },

    // 设置审核开关
    examineFormChange(type, value) {
      const confirm = () => {
        const check = value ? 1 : 0
        const data = Object.assign({}, this.comprehensiveForm, {
          [type]: check
        })
        this.comprehensiveForm = data
      }
      if (value) {
        this.$confirm(this.$t('当前状态改变后对业务可能造成影响和风险,请慎重操作'), this.$t('提示'), {
          type: 'warning'
        }).then(() => {
          confirm()
        }).catch(() => {
        })
      } else {
        confirm()
      }
    },
    //关于我们设置提交
    async visibleAboutConfirm() {
      const {productName} = this.tableRows
      const res = await replaceInsertAbout({
        ...this.aboutForm,
        productName
      })
      if (res.code === 1) {
        this.$message.success(this.$t('编辑成功'))
        this.visibleAbout = false
      }
    },
    setAuditProcess() {
      this.auditForm = {
        newIsFirstTrial: this.tableRows.newIsFirstTrial || 0,
        oldIsFirstTrial: this.tableRows.oldIsFirstTrial || 0,
      }
      this.visibleAuditProcess = true
    },
    // 切换审核状态
    changeAuditProcess(type) {
      let {newIsFirstTrial, oldIsFirstTrial} = this.auditForm
      if (type === 'new') {
        newIsFirstTrial === 0 ? this.auditForm.newIsFirstTrial = 1 : this.auditForm.newIsFirstTrial = 0
      } else {
        oldIsFirstTrial === 0 ? this.auditForm.oldIsFirstTrial = 1 : this.auditForm.oldIsFirstTrial = 0
      }
    },
    // 审核状态提交
    async confirmAuditProcess() {
      const {adminProductId} = this.tableRows
      const res = await firstTrialSwitch({productId: adminProductId, ...this.auditForm})
      if (res.code === 1) {
        this.$message({
          duration: 3000,
          type: 'success',
          message: this.$t('操作成功')
        })
        this.visibleAuditProcess = false
        this.getTableData()
      }
    },
    //
    aboutClearForm() {
      this.aboutForm = {}
      this.$refs.aboutForm.resetFields()
    },
    look(row) {
      this.$router.push({
        path: '/product/productConfig',
        query: {
          productId: row.adminProductId,
          productName: row.productName,
          permissId: 128
        }
      })
    }
  }
}
</script>

<style scoped lang="less">

.comprehensive_box {
  padding-left: 10px;

  .title {
    font-size: 16px;
    font-family: PingFang SC;
    font-weight: bold;
    color: #000000;
    border-bottom: 1px solid #EEEEEE;
    padding-bottom: 10px;
  }

  .content {
    padding: 15px 10px 15px 0;

    ::v-deep .el-input-group {
      width: 0% !important;

    }

    ::v-deep .el-input__inner {
      width: 70px !important;
    }


  }
}

.audit_text {
  width: 120px;
  text-align: center;
  background: #DBDBDB;
  font-size: 16px;
  padding: 5px 5px;
  border-radius: 14px;
}

.audit_text_active {
  background: #F1B901 !important;
  color: #ffffff;
}
</style>
